package com.ruoyi.warehousemanager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.injector.methods.DeleteBatchByIds;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.warehousemanager.domain.Check;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehousemanager.domain.NewApply;
import com.ruoyi.warehousemanager.service.INewApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购Controller
 *
 * @author zyx
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/warehousemanager/procure")
public class NewApplyController extends BaseController {
    @Autowired
    private INewApplyService newApplyService;

    /**
     * 查询采购列表
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:procure:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewApply newApply) {
        startPage();
        List<NewApply> list = newApplyService.selectNewApplyList(newApply);
        return getDataTable(list);
    }

    //按照条件查询列表数据
    @PreAuthorize("@ss.hasPermi('warehousemanager:procure:list')")
    @GetMapping("/listByQuery")
    public TableDataInfo listByQuery(String begin,String end) {
        startPage();
        List<NewApply> list = newApplyService.selectNewApplyByTimeRange(begin, end);
        return getDataTable(list);
    }

    /**
     * 导出采购列表
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:procure:export')")
    @Log(title = "采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, String begin,String end) {
        List<NewApply> list = newApplyService.selectNewApplyByTimeRange(begin, end);
        ExcelUtil<NewApply> util = new ExcelUtil<NewApply>(NewApply.class);
        util.exportExcel(response, list, "采购数据");
    }

    /**
     * 新增采购管理
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:procure:add')")
    @Log(title = "采购管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewApply newApply) {
        return toAjax(newApplyService.insertNewApply(newApply));
    }


    /**
     * 删除采购信息
     */
    @PreAuthorize("@ss.hasPermi('warehousemanager:procure:remove')")
    @Log(title = "采购管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{newApplyIds}")
    public AjaxResult remove(@PathVariable Long[] newApplyIds) {
        return toAjax(newApplyService.deleteNewApplyByIds(newApplyIds));
    }

}
